<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Health;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class HealthController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Health(), function (Grid $grid) {
            $grid->column('id','序号')->sortable();
            $grid->column('title');
            $grid->column('content');
            $grid->column('author');
            $grid->column('cover','封面');
            $grid->column('apply_person','适用人群');
            $grid->column('illness_type');
            $grid->column('measure');
            $grid->column('method');
            $grid->column('drug');
            $grid->column('attention');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Health(), function (Show $show) {
            $show->field('id');
            $show->field('title');
            $show->field('content');
            $show->field('author');
            $show->field('cover');
            $show->field('apply_person');
            $show->field('illness_type');
            $show->field('measure');
            $show->field('method');
            $show->field('drug');
            $show->field('attention');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Health(), function (Form $form) {
            $form->display('id');
            $form->text('title');
            $form->text('content');
            $form->text('author');
            $form->image('cover','封面');
            $form->radio('apply_person','适用人群')->options([
                0 => '成人', 1 => '儿童', 2 => '老年'
            ]);
            $form->radio('illness_type','疾病分类')->options([
                0=>'传染病',1=>'急性病',2=>'慢性病',3=>'遗传性疾病',4=>'呼吸系统疾病',5=>'消化系统疾病',6=>'肌肉骨骼系统疾病',7=>'其他'
            ]);
            $form->textarea('measure');
            $form->textarea('method');
            $form->text('drug');
            $form->textarea('attention');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
